//
//  MainPosterCollection.m
//  项目1 CLCMovie
//
//  Created by huiwenjiaoyu on 15/7/24.
//  Copyright (c) 2015年 CLC. All rights reserved.
//

#import "MainPosterCollection.h"
#define kWidth  [UIScreen mainScreen].bounds.size.width
#define kHieght [UIScreen mainScreen].bounds.size.height
#import "UIViewExt.h"


@implementation MainPosterCollection

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    
    if (self) {

        self.dataSource = self;
        self.delegate = self;
    

        [self registerClass:[MainPosterCollectionViewCell class] forCellWithReuseIdentifier:@"mainPosterCell"];
    }
    
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [_modalArray count];
}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
    
    
    CGFloat x = targetContentOffset->x;
    NSInteger i = x/(kWidth*3/4);
    targetContentOffset->x = kWidth*7/8*i;
    
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    MainPosterCollectionViewCell* Cell = (MainPosterCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
    
    [Cell flipCell];
    
}

//- (void)flipCell:(NSInteger)index
//{
////    MainPosterCollectionViewCell* cell = (MainPosterCollectionViewCell*)[self viewWithTag:200+index];
//    MainPosterCollectionViewCell* cell = [self cellForItemAtIndexPath: ]
//    [UIView transitionWithView:self duration:0.1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:nil completion:nil];
//    if(cell.isDetail)
//    {
//        cell.detailView.hidden = YES;
//        cell.mainPoster.hidden = NO;
//        NSLog(@"1");
//    }
//    else
//    {
//        cell.detailView.hidden = NO;
//        cell.mainPoster.hidden = YES;
//        NSLog(@"2");
//    }
//    cell.isDetail =! cell.isDetail;
//}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MainPosterCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"mainPosterCell" forIndexPath:indexPath];
    
    cell.modal = _modalArray[indexPath.row];
    cell.tag = 200+indexPath.row;

    

    NSLog(@"%ld",cell.tag);
    
    return cell;





}



@end
